#include "rclcpp/rclcpp.hpp"
#include "geometry_msgs/msg/twist.hpp"
#include <chrono>
using namespace std::chrono_literals; //可以使⽤毫秒格式输入时间
class TurtleCircleNode : public rclcpp::Node
{
private:
 rclcpp::Publisher<geometry_msgs::msg::Twist>::SharedPtr publisher; // 声明智能指针
 rclcpp::TimerBase::SharedPtr timer;
public:
 explicit TurtleCircleNode(const std::string &node_name) : Node(node_name)
 {
 publisher = this->create_publisher<geometry_msgs::msg::Twist>
("/turtle1/cmd_vel", 10);
 timer = this->create_wall_timer(1000ms,
std::bind(&TurtleCircleNode::timer_callback, this)); // 成员⽅法在使⽤时需要进⾏bind操作，使⽤引⽤的⽅式。
 }
 void timer_callback()
 {
 auto msg = geometry_msgs::msg::Twist();
 msg.linear.x = 1.0;
 msg.angular.z = 0.5;
 publisher->publish(msg);
 }
};
int main(int argc, char **argv)
{
 rclcpp::init(argc, argv);
 auto node=std::make_shared<TurtleCircleNode>("turtle_circle");
 rclcpp::spin(node);
 rclcpp::shutdown();
 return 0;
}